﻿#region Using Statements

using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using Merbla.Coffee.Web.Core;
using Microsoft.Practices.ServiceLocation;
using Microsoft.Practices.Unity;


#endregion

namespace Merbla.Coffee.Web
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : HttpApplication
    {
        private static readonly object behaviorInitializationSyncObject = new object();

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new {controller = "Home", action = "Index", id = ""} // Parameter defaults
                );
        }


        protected void Application_Start()
        {
            //ControllerBuilder
            RegisterRoutes(RouteTable.Routes);


            ConfigureContainer();
            ControllerBuilder.Current.SetControllerFactory(new CommonServiceLocatorControllerFactory());
        }


        private void ConfigureContainer()
        {
            IUnityContainer container = new UnityContainer();

            //container.RegisterType<ITest, Test>();

            //container.RegisterType<IMembershipService, AccountMembershipService>();

            //container.RegisterType<IFormsAuthentication, FormsAuthenticationService>();
            //container.RegisterType<AccountController, AccountController>();

            //container.RegisterType<UserController, UserController>();
            //container.RegisterType<OpenIdController, OpenIdController>();


            ServiceLocator.SetLocatorProvider(() => new UnityServiceLocator(container));
        }
    }
}